package com.pjmike.common.controller;

import com.pjmike.common.service.TestService;
import com.pjmike.common.util.thread.MyFutureTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user/")
/**
 *  这个模拟多个接口合并请求 和多个接口分开请求 耗时情况
 */
public class TestController {

    private static final Logger log= LoggerFactory.getLogger(TestController.class);

    @Autowired
    private TestService testService;
    @Autowired
    private MyFutureTask myFutureTask;

    @RequestMapping("/index")
    @ResponseBody
    public String index(){
        return "启动用户模块成功~~~~~~~~";
    }


    @GetMapping("/get/data")
    @ResponseBody
    public long getUserData(Long userId){
        log.info("UserController的线程:" + Thread.currentThread());
        long begin = System.currentTimeMillis();
        long result = myFutureTask.getUserAggregatedResult(userId);
        long end = System.currentTimeMillis();
        log.info("===============总耗时:" + (end - begin) /1000.0000+ "秒");
        return result;
    }


}
